

#import "FAMTool.h"
#import <sys/utsname.h>
@implementation FAMTool
+ (NSString *)FAM_getUUID{
    NSString *uuid = [SAMKeychain passwordForService:@"FoodAIMate" account:@"uuid"];
    if (uuid.length == 0) {
        uuid = [[UIDevice currentDevice]identifierForVendor].UUIDString;
        uuid = [uuid stringByReplacingOccurrencesOfString:@"-" withString:@""];
        [SAMKeychain setPassword:uuid forService:@"FoodAIMate" account:@"uuid"];
    }
    return uuid;
}
+ (NSString *)FAM_getDeviceBrand {
    return [UIDevice currentDevice].model;
}
+ (NSString *)FAM_getCurrentLanguage {
    NSArray *languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
    if (languages.count > 0) {
        return languages.firstObject;
    }
    return @"en-CN";
}
+ (NSString *)FAM_getNowTimeTimestamp{
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    formatter.dateStyle = NSDateFormatterMediumStyle;
    formatter.timeStyle = NSDateFormatterShortStyle;
    formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    formatter.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"Asia/Beijing"];
    NSDate *dateNow = [[NSDate alloc]init];
    NSString *timeSp = [NSString stringWithFormat:@"%0.f",[dateNow timeIntervalSince1970] *1000];
    return timeSp;
}
+ (NSString *)FAM_getDeviceModel{
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *deviceModel = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];

    //iPhone 系列
    if ([deviceModel isEqualToString:@"iPhone1,1"]) return @"iPhone 1G";
    if ([deviceModel isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
    if ([deviceModel isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
    if ([deviceModel isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
    if ([deviceModel isEqualToString:@"iPhone3,2"]) return @"Verizon iPhone 4";
    if ([deviceModel isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
    if ([deviceModel isEqualToString:@"iPhone5,1"]) return @"iPhone 5";
    if ([deviceModel isEqualToString:@"iPhone5,2"]) return @"iPhone 5";
    if ([deviceModel isEqualToString:@"iPhone5,3"]) return @"iPhone 5C";
    if ([deviceModel isEqualToString:@"iPhone5,4"]) return @"iPhone 5C";
    if ([deviceModel isEqualToString:@"iPhone6,1"]) return @"iPhone 5S";
    if ([deviceModel isEqualToString:@"iPhone6,2"]) return @"iPhone 5S";
    if ([deviceModel isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus";
    if ([deviceModel isEqualToString:@"iPhone7,2"]) return @"iPhone 6";
    if ([deviceModel isEqualToString:@"iPhone8,1"]) return @"iPhone 6s";
    if ([deviceModel isEqualToString:@"iPhone8,2"]) return @"iPhone 6s Plus";
    if ([deviceModel isEqualToString:@"iPhone8,4"]) return @"iPhone se";
    if ([deviceModel isEqualToString:@"iPhone9,1"]) return @"iPhone 7";
    if ([deviceModel isEqualToString:@"iPhone9,3"]) return @"iPhone 7";
    if ([deviceModel isEqualToString:@"iPhone9,2"]) return @"iPhone 7 Plus";
    if ([deviceModel isEqualToString:@"iPhone9,4"]) return @"iPhone 7 Plus";
    if ([deviceModel isEqualToString:@"iPhone10,1"]) return @"iPhone 8";
    if ([deviceModel isEqualToString:@"iPhone10,4"]) return @"iPhone 8";
    if ([deviceModel isEqualToString:@"iPhone10,2"]) return @"iPhone 8 Plus";
    if ([deviceModel isEqualToString:@"iPhone10,5"]) return @"iPhone 8 Plus";
    if ([deviceModel isEqualToString:@"iPhone10,3"]) return @"iPhone X";
    if ([deviceModel isEqualToString:@"iPhone10,6"]) return @"iPhone X";
    if ([deviceModel isEqualToString:@"iPhone11,8"]) return @"iPhone XR";
    if ([deviceModel isEqualToString:@"iPhone11,2"]) return @"iPhone XS";
    if ([deviceModel isEqualToString:@"iPhone11,6"]) return @"iPhone XS Max";
    if ([deviceModel isEqualToString:@"iPhone12,1"]) return @"iPhone 11";
    if ([deviceModel isEqualToString:@"iPhone12,3"]) return @"iPhone 11 Pro";
    if ([deviceModel isEqualToString:@"iPhone12,5"]) return @"iPhone 11 Pro Max";
    if ([deviceModel isEqualToString:@"iPhone12,8"]) return @"iPhone SE (2nd generation)";
    if ([deviceModel isEqualToString:@"iPhone13,1"]) return @"iPhone 12 mini";
    if ([deviceModel isEqualToString:@"iPhone13,2"]) return @"iPhone 12";
    if ([deviceModel isEqualToString:@"iPhone13,3"]) return @"iPhone 12 Pro";
    if ([deviceModel isEqualToString:@"iPhone13,4"]) return @"iPhone 12 Pro Max";
    if ([deviceModel isEqualToString:@"iPhone14,4"]) return @"iPhone 13 mini";
    if ([deviceModel isEqualToString:@"iPhone14,5"]) return @"iPhone 13";
    if ([deviceModel isEqualToString:@"iPhone14,2"]) return @"iPhone 13 Pro";
    if ([deviceModel isEqualToString:@"iPhone14,3"]) return @"iPhone 13 Pro Max";
    if ([deviceModel isEqualToString:@"iPhone14,6"]) return @"iPhone SE (3rd generation)";
    if ([deviceModel isEqualToString:@"iPhone14,7"]) return @"iPhone 14";
    if ([deviceModel isEqualToString:@"iPhone14,8"]) return @"iPhone 14 Plus";
    if ([deviceModel isEqualToString:@"iPhone15,2"]) return @"iPhone 14 Pro";
    if ([deviceModel isEqualToString:@"iPhone15,3"]) return @"iPhone 14 Pro Max";
//    if ([deviceModel isEqualToString:@"iPhone14,8"]) return @"iPhone 14 Plus";
//    if ([deviceModel isEqualToString:@"iPhone14,8"]) return @"iPhone 14 Plus";
//    if ([deviceModel isEqualToString:@"iPhone14,8"]) return @"iPhone 14 Plus";
//    if ([deviceModel isEqualToString:@"iPhone14,8"]) return @"iPhone 14 Plus";
    
    
    
    //iPod 系列
    if ([deviceModel isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G";
    if ([deviceModel isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G";
    if ([deviceModel isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G";
    if ([deviceModel isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G";
    if ([deviceModel isEqualToString:@"iPod5,1"]) return @"iPod Touch 5G";

    //iPad 系列
    if ([deviceModel isEqualToString:@"iPad1,1"]) return @"iPad";
    if ([deviceModel isEqualToString:@"iPad2,1"]) return @"iPad 2 (WiFi)";
    if ([deviceModel isEqualToString:@"iPad2,2"]) return @"iPad 2 (GSM)";
    if ([deviceModel isEqualToString:@"iPad2,3"]) return @"iPad 2 (CDMA)";
    if ([deviceModel isEqualToString:@"iPad2,4"]) return @"iPad 2 (32nm)";
    if ([deviceModel isEqualToString:@"iPad2,5"]) return @"iPad mini (WiFi)";
    if ([deviceModel isEqualToString:@"iPad2,6"]) return @"iPad mini (GSM)";
    if ([deviceModel isEqualToString:@"iPad2,7"]) return @"iPad mini (CDMA)";

    if ([deviceModel isEqualToString:@"iPad3,1"]) return @"iPad 3(WiFi)";
    if ([deviceModel isEqualToString:@"iPad3,2"]) return @"iPad 3(CDMA)";
    if ([deviceModel isEqualToString:@"iPad3,3"]) return @"iPad 3(4G)";
    if ([deviceModel isEqualToString:@"iPad3,4"]) return @"iPad 4 (WiFi)";
    if ([deviceModel isEqualToString:@"iPad3,5"]) return @"iPad 4 (4G)";
    if ([deviceModel isEqualToString:@"iPad3,6"]) return @"iPad 4 (CDMA)";

    if ([deviceModel isEqualToString:@"iPad4,1"]) return @"iPad Air";
    if ([deviceModel isEqualToString:@"iPad4,2"]) return @"iPad Air";
    if ([deviceModel isEqualToString:@"iPad4,3"]) return @"iPad Air";
    if ([deviceModel isEqualToString:@"iPad5,3"]) return @"iPad Air 2";
    if ([deviceModel isEqualToString:@"iPad5,4"]) return @"iPad Air 2";
    if ([deviceModel isEqualToString:@"i386"]) return @"Simulator";
    if ([deviceModel isEqualToString:@"x86_64"]) return @"Simulator";

    if ([deviceModel isEqualToString:@"iPad4,4"]
    ||[deviceModel isEqualToString:@"iPad4,5"]
    ||[deviceModel isEqualToString:@"iPad4,6"]) return @"iPad mini 2";

    if ([deviceModel isEqualToString:@"iPad4,7"]
    ||[deviceModel isEqualToString:@"iPad4,8"]
    ||[deviceModel isEqualToString:@"iPad4,9"]) return @"iPad mini 3";

    return deviceModel;
}
+ (NSString *)FAM_getOSCode {
    return [[UIDevice currentDevice] systemVersion];
}
+ (NSString *)FAM_getAppId{
    return @"1957262640";
}
+ (NSString *)FAM_getAppKey{
    return @"22f570c42df14371a34beaf3839de711";
}
+ (NSString *)FAM_getYearWithMonthWithDay{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateStyle = NSDateFormatterMediumStyle;
    dateFormatter.timeStyle = NSDateFormatterShortStyle;
    dateFormatter.dateFormat = @"yyyyMMdd";
    dateFormatter.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"Asia/Beijing"];
    NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
    return dateString;
}
+ (NSInteger)FAM_getCurrentHH{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateStyle = NSDateFormatterMediumStyle;
    dateFormatter.timeStyle = NSDateFormatterShortStyle;
    dateFormatter.dateFormat = @"HH";
    dateFormatter.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"Asia/Beijing"];
    NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
    return dateString.integerValue;
}
+ (NSString *)FAM_getMonthWithDay{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateStyle = NSDateFormatterMediumStyle;
    dateFormatter.timeStyle = NSDateFormatterShortStyle;
    dateFormatter.dateFormat = @"MM.dd";
    dateFormatter.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"Asia/Beijing"];
    NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
    return dateString;
}
+ (NSMutableAttributedString *)FAM_AttributedString:(NSString *)styleOneString styleTwoString:(NSString *)styleTwoString styleColorOne:(UIColor *)styleColorOne styleColorTwo:(UIColor *)styleColorTwo styleFontOne:(int)styleFontOne styleFontTwo:(int)styleFontTwo{
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@ %@",styleOneString,styleTwoString]];
    [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:styleFontOne] range:[[NSString stringWithFormat:@"%@ %@",styleOneString,styleTwoString] rangeOfString:styleOneString]];
    [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:styleFontTwo] range:[[NSString stringWithFormat:@"%@ %@",styleOneString,styleTwoString] rangeOfString:styleTwoString]];
    [attributedString addAttribute:NSForegroundColorAttributeName value:styleColorOne range:[[NSString stringWithFormat:@"%@ %@",styleOneString,styleTwoString] rangeOfString:styleOneString]];
    [attributedString addAttribute:NSForegroundColorAttributeName value:styleColorTwo range:[[NSString stringWithFormat:@"%@ %@",styleOneString,styleTwoString] rangeOfString:styleTwoString]];
    return attributedString;
}
+ (NSString *)FAM_getMonth:(NSDate *)date{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateStyle = NSDateFormatterMediumStyle;
    dateFormatter.timeStyle = NSDateFormatterShortStyle;
    dateFormatter.dateFormat = @"MM";
    dateFormatter.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"Asia/Beijing"];
    NSString *dateString = [dateFormatter stringFromDate:date];
    if ([dateString isEqualToString:@"1"]) {
        return @"January";
    }else if ([dateString isEqualToString:@"2"]){
        return  @"February";
    }else if ([dateString isEqualToString:@"3"]){
        return  @"March";
    }else if ([dateString isEqualToString:@"4"]){
        return  @"April";
    }else if ([dateString isEqualToString:@"5"]){
        return  @"May";
    }else if ([dateString isEqualToString:@"6"]){
        return  @"June";
    }else if ([dateString isEqualToString:@"7"]){
        return  @"July";
    }else if ([dateString isEqualToString:@"8"]){
        return  @"August";
    }else if ([dateString isEqualToString:@"9"]){
        return  @"September";
    }else if ([dateString isEqualToString:@"10"]){
        return  @"October";
    }else if ([dateString isEqualToString:@"11"]){
        return  @"November";
    }else{
        return  @"December";
    }
    
}
+ (NSString *)FAM_getDay:(NSDate *)date{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateStyle = NSDateFormatterMediumStyle;
    dateFormatter.timeStyle = NSDateFormatterShortStyle;
    dateFormatter.dateFormat = @"dd";
    dateFormatter.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"Asia/Beijing"];
    NSString *dateString = [dateFormatter stringFromDate:date];
    return dateString;
}
+ (NSString *)FAM_getWeak:(NSDate *)date{
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSCalendarUnit unitFlags = NSCalendarUnitWeekday;
    NSDateComponents *dateComponents = [calendar components:unitFlags fromDate:date];
    NSInteger weekday = dateComponents.weekday;
    if (weekday == 0) {
        return @"Sunday";
    }else if (weekday == 1){
        return @"Monday";
    }else if (weekday == 2){
        return @"Tuesday";
    }else if (weekday == 3){
        return @"Wednesday";
    }else if (weekday == 4){
        return @"Thursday";
    }else if (weekday == 5){
        return @"Friday";
    }else{
        return @"Saturday";
    }
}
+ (NSString *)FAM_getYearWithMonthWithDay:(NSDate *)date{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateStyle = NSDateFormatterMediumStyle;
    dateFormatter.timeStyle = NSDateFormatterShortStyle;
    dateFormatter.dateFormat = @"yyyyMMdd";
    dateFormatter.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"Asia/Beijing"];
    NSString *dateString = [dateFormatter stringFromDate:date];
    return dateString;
}
@end
